#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
 
typedef long long LL;
 
const int maxn = 2e5 + 10;
 
LL sum[maxn];
LL sz[maxn];
LL color[maxn];
bool used[maxn];
vector<int> tree[maxn];
LL ans;
int n;
 
LL dfs(int u, int fa){
    sz[u] = 1;
    LL allson = 0;
    for (int i=0; i<tree[u].size(); i++){
        int v = tree[u][i];
        if (v == fa) continue;
        LL last = sum[color[u]];
        sz[u] += dfs(v, u);
        LL add = sum[color[u]] - last;
        ans += (sz[v] - add) * (sz[v] - add - 1LL) / 2LL;
        allson += sz[v] - add;
    }
    sum[color[u]] += allson + 1;
 
    return sz[u];
}
 
int main(){
    int t = 0;
 
    while (~scanf("%d", &n)){
        t++;
        memset(used, false, sizeof(used));
        memset(sum, 0, sizeof(sum));
 
        int cnt = 0;
        for (int i=1; i<=n; i++){
            scanf("%I64d", &color[i]);
            if (!used[color[i]]) cnt++;
            used[color[i]] = true;
            tree[i].clear();
        }
        for (int i=0; i<n-1; i++){
            int u, v;
            scanf("%d%d", &u, &v);
            tree[u].push_back(v);
            tree[v].push_back(u);
        }
 
        ans = 0;
        dfs(1, -1);
        for (int i=1; i<=n; i++){
            if (!used[i]) continue;
            ans += ((LL)n - sum[i]) * ((LL)n - sum[i] - 1LL) / 2LL;
        }
        printf("Case #%d: %I64d\n", t, (LL)cnt*(LL)n*(LL)(n-1LL)/2LL - (LL)ans);
    }
}